package StudyCode.summary.zipfile;

import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ExtractsEntryFromZipFileIntoDest {
	public static void ExtractFromZip(ZipFile zf, ZipEntry entry, File dest)
			throws IOException {
		if (entry.isDirectory()) {
			dest.mkdirs();
			return;
		}

		dest.getParentFile().mkdirs();

		if (!dest.exists())
			dest.createNewFile();

		int bufSize = 1024;

		InputStream is = zf.getInputStream(entry);
		BufferedInputStream in = new BufferedInputStream(is, bufSize);

		FileOutputStream fos = new FileOutputStream(dest);
		BufferedOutputStream out = new BufferedOutputStream(fos, bufSize);

		int count = 0;
		byte[] buffer = new byte[bufSize];
		while ((count = in.read(buffer, 0, buffer.length)) != -1) {
			out.write(buffer, 0, count);
		}
		out.flush();
		out.close();
		is.close();
	}
}
